package com.campol.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.IBinder;

public class LocationService extends Service implements LocationListener {

	private static final int DEFAULT_DISTANCE = 1000; //meters
	private static final int DEFAULT_TIME = 300000;//5 min
	
	private LocationManager lmManager;
	
	@Override
	public void onCreate() {
		super.onCreate();
		
		lmManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		lmManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, DEFAULT_TIME, DEFAULT_DISTANCE, this);
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public void onDestroy() {
		lmManager.removeUpdates(this);
		super.onDestroy();
	}	

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	// LOCATION LISTENER METHODS
	@Override
	public void onLocationChanged(Location location) {
		new CheckPoliceTask(location).start();
	}

	@Override
	public void onProviderDisabled(String provider) {
	}

	@Override
	public void onProviderEnabled(String provider) {
	}

	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
	}
	
	private class CheckPoliceTask extends Thread {

		private Location mLocation;
		
		public CheckPoliceTask(Location location) {
			this.mLocation = location;
		}
		
		@Override
		public void run() {
			//TODO stuff to 
		}
		
	}
}
